package com.project.service.impl;

import com.project.bean.ClassBean;
import com.project.mapper.IClassMapper;
import com.project.mapper.IStudentMapper;
import com.project.service.IClassService;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class ClassServiceImpl extends BaseService implements IClassService{
    @Override
    public List<ClassBean> findAll() {
        SqlSession session = this.getSession();
        IClassMapper mapper = session.getMapper(IClassMapper.class);
        List<ClassBean> list = mapper.findAll();
        session.close();
        return list;
    }

    @Override
    public void add(ClassBean classBean) {
        SqlSession session = this.getSession();
        IClassMapper mapper = session.getMapper(IClassMapper.class);
        mapper.add(classBean);
        session.commit();
        session.close();
    }

    @Override
    public boolean del(int id) {
        SqlSession session = this.getSession();
        IClassMapper cMapper = session.getMapper(IClassMapper.class);
        IStudentMapper sMapper = session.getMapper(IStudentMapper.class);
        if (sMapper.countByClass(id)!=0){
            return false;
        }
        cMapper.del(id);
        session.commit();
        session.close();
        return true;
    }
}
